﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace QLBH.FeatureBase
{
    public class DialogBase:Form
    {
        private DevComponents.DotNetBar.Bar bar1;
        private DevComponents.DotNetBar.ButtonItem btnThem;
        private DevComponents.DotNetBar.ButtonItem btnSua;
        private DevComponents.DotNetBar.ButtonItem btnXoa;
        private DevComponents.DotNetBar.ButtonItem btnNapLai;
        private DevComponents.DotNetBar.TextBoxItem tbxSearchInput;

        public DevComponents.DotNetBar.TextBoxItem TbxSearchInput
        {
            get { return tbxSearchInput; }
            set { tbxSearchInput = value; }
        }
        private DevComponents.DotNetBar.ButtonItem btnTimKiem;

        public DevComponents.DotNetBar.ButtonItem BtnTimKiem
        {
            get { return btnTimKiem; }
            set { btnTimKiem = value; }
        }
        private DataGridView dataGridView1;

        public DataGridView DataGridView
        {
            get { return dataGridView1; }
            set { dataGridView1 = value; }
        }
        private TableLayoutPanel tableLayoutPanel1;

        private object dataSource;

        public object DataSource
        {
            get { return dataSource; }
            set { dataSource = value; }
        }
    
        private void InitializeComponent()
        {
            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.bar1 = new DevComponents.DotNetBar.Bar();
            this.btnThem = new DevComponents.DotNetBar.ButtonItem();
            this.btnSua = new DevComponents.DotNetBar.ButtonItem();
            this.btnXoa = new DevComponents.DotNetBar.ButtonItem();
            this.btnNapLai = new DevComponents.DotNetBar.ButtonItem();
            this.tbxSearchInput = new DevComponents.DotNetBar.TextBoxItem();
            this.btnTimKiem = new DevComponents.DotNetBar.ButtonItem();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.tableLayoutPanel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.bar1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // tableLayoutPanel1
            // 
            this.tableLayoutPanel1.ColumnCount = 1;
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tableLayoutPanel1.Controls.Add(this.bar1, 0, 0);
            this.tableLayoutPanel1.Controls.Add(this.dataGridView1, 0, 1);
            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = 2;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(718, 448);
            this.tableLayoutPanel1.TabIndex = 0;
            // 
            // bar1
            // 
            this.bar1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.bar1.DockSide = DevComponents.DotNetBar.eDockSide.Document;
            this.bar1.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] {
            this.btnThem,
            this.btnSua,
            this.btnXoa,
            this.btnNapLai,
            this.tbxSearchInput,
            this.btnTimKiem});
            this.bar1.Location = new System.Drawing.Point(0, 0);
            this.bar1.Margin = new System.Windows.Forms.Padding(0);
            this.bar1.Name = "bar1";
            this.bar1.Size = new System.Drawing.Size(718, 25);
            this.bar1.Stretch = true;
            this.bar1.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2007;
            this.bar1.TabIndex = 0;
            this.bar1.TabStop = false;
            this.bar1.Text = "bar1";
            // 
            // btnThem
            // 
            this.btnThem.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText;
            this.btnThem.Image = global::QLBH.FeatureBase.Properties.Resources.add_1_icon;
            this.btnThem.ImagePaddingHorizontal = 8;
            this.btnThem.Name = "btnThem";
            this.btnThem.Shortcuts.Add(DevComponents.DotNetBar.eShortcut.CtrlN);
            this.btnThem.Text = "Thêm mới (Ctrl+N)";
            this.btnThem.Click += new System.EventHandler(this.btnThem_Click);
            // 
            // btnSua
            // 
            this.btnSua.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText;
            this.btnSua.Image = global::QLBH.FeatureBase.Properties.Resources.edit_icon;
            this.btnSua.ImagePaddingHorizontal = 8;
            this.btnSua.Name = "btnSua";
            this.btnSua.Shortcuts.Add(DevComponents.DotNetBar.eShortcut.CtrlE);
            this.btnSua.Text = "Sửa (Ctrl +E)";
            this.btnSua.Click += new System.EventHandler(this.btnSua_Click);
            // 
            // btnXoa
            // 
            this.btnXoa.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText;
            this.btnXoa.Image = global::QLBH.FeatureBase.Properties.Resources.delete_icon;
            this.btnXoa.ImagePaddingHorizontal = 8;
            this.btnXoa.Name = "btnXoa";
            this.btnXoa.Shortcuts.Add(DevComponents.DotNetBar.eShortcut.Del);
            this.btnXoa.Text = "Xóa (Del)";
            this.btnXoa.Click += new System.EventHandler(this.btnXoa_Click);
            // 
            // btnNapLai
            // 
            this.btnNapLai.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText;
            this.btnNapLai.Image = global::QLBH.FeatureBase.Properties.Resources.Refresh_icon16;
            this.btnNapLai.ImagePaddingHorizontal = 8;
            this.btnNapLai.Name = "btnNapLai";
            this.btnNapLai.Shortcuts.Add(DevComponents.DotNetBar.eShortcut.F5);
            this.btnNapLai.Text = "Nạp lại (F5)";
            this.btnNapLai.Click += new System.EventHandler(this.btnNapLai_Click);
            // 
            // tbxSearchInput
            // 
            this.tbxSearchInput.ItemAlignment = DevComponents.DotNetBar.eItemAlignment.Far;
            this.tbxSearchInput.Name = "tbxSearchInput";
            this.tbxSearchInput.TextBoxWidth = 150;
            this.tbxSearchInput.WatermarkColor = System.Drawing.SystemColors.GrayText;
            this.tbxSearchInput.WatermarkText = "Nhập từ khóa cần tìm";
            // 
            // btnTimKiem
            // 
            this.btnTimKiem.Image = global::QLBH.FeatureBase.Properties.Resources.search_icon16;
            this.btnTimKiem.ImagePaddingHorizontal = 8;
            this.btnTimKiem.Name = "btnTimKiem";
            this.btnTimKiem.SplitButton = true;
            this.btnTimKiem.Text = "buttonItem6";
            // 
            // dataGridView1
            // 
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
            this.dataGridView1.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dataGridView1.Location = new System.Drawing.Point(3, 28);
            this.dataGridView1.MultiSelect = false;
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            this.dataGridView1.ShowEditingIcon = false;
            this.dataGridView1.Size = new System.Drawing.Size(712, 417);
            this.dataGridView1.TabIndex = 1;
            this.dataGridView1.DataSourceChanged += new System.EventHandler(this.dataGridView1_DataSourceChanged);
            this.dataGridView1.CellContentDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentDoubleClick);
            // 
            // DialogBase
            // 
            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(125)))), ((int)(((byte)(125)))), ((int)(((byte)(125)))));
            this.ClientSize = new System.Drawing.Size(718, 448);
            this.Controls.Add(this.tableLayoutPanel1);
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.KeyPreview = true;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "DialogBase";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Load += new System.EventHandler(this.DialogBase_Load);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.DialogBase_KeyDown);
            this.tableLayoutPanel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.bar1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);

        }
        public DialogBase()
        {
            InitializeComponent();

            dataGridView1.RowPostPaint += new DataGridViewRowPostPaintEventHandler(dataGridView1_RowPostPaint);
        }
        void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
            {
                e.Graphics.DrawString(e.RowIndex.ToString(), e.InheritedRowStyle.Font, b,
                    e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4);

            }
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            AddNew(sender, e);
        }
#region Virtual method
        public virtual void AddNew(object sender, EventArgs e)
        {

        }
        public virtual void Edit(object sender, EventArgs e)
        {

        }
        public virtual void Delete(object sender, EventArgs e)
        {

        }
        public virtual void RefreshData(object sender, EventArgs e)
        {

        }
        public virtual void SaveData(object sender, EventArgs e)
        {

        }
        public virtual void BuildSearchMenu()
        {

        }
        public virtual void FormLoaded(object sender, EventArgs e)
        {
            
        }
#endregion

        private void btnSua_Click(object sender, EventArgs e)
        {
            Edit(sender, e);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            Delete(sender, e);
        }

        private void btnNapLai_Click(object sender, EventArgs e)
        {
            RefreshData(sender, e);
        }

        private void btnGhi_Click(object sender, EventArgs e)
        {
            SaveData(sender, e);
        }

        private void DialogBase_Load(object sender, EventArgs e)
        {
            BuildSearchMenu();
            RefreshData(sender, e);
            FormLoaded(sender, e);
        }

        private void dataGridView1_DataSourceChanged(object sender, EventArgs e)
        {
            if (DataGridView.RowCount>0)
            {
                btnXoa.Enabled = true;
                btnSua.Enabled = true;
            }
            else
            {
                btnSua.Enabled = false;
                btnXoa.Enabled = false;
            }
        }

        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Edit(sender, null);
        }

        private void DialogBase_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
        }

    }
}
